package com.java.threadsafe.unvsafe;

/*
 * 变量安全问题
 * @author Administrator
 *
 */
public class ThreadEntity implements Runnable {
	// 尽量不要定义全局变量
	int num = 1;
	
	@Override
	public void run() {
		for(int i=0; i<5; i++) {
			++num; 
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println(Thread.currentThread().getName() + " ---- " + num);
		}
	}

}
